package com.xrz.sxm.base.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
public class VersonUtil {

	public static String getAPKFileVersonName(Context ctx, String apkPath){
		String version = "";
		PackageManager pm = ctx.getPackageManager();      
        PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);      
        if(info != null){      
            ApplicationInfo appInfo = info.applicationInfo;      
            String appName = pm.getApplicationLabel(appInfo).toString();      
            String packageName = appInfo.packageName;
            version=info.versionName;
        }    
        return version;
	}
	
	public static String getVisionName(Context ctx) {
		String visionName = "";
		try {
			PackageManager pm = ctx.getPackageManager();
			PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), 0);
			visionName = pi.versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return visionName;
	}
	
	public static int getVisionCode(Context ctx) {
		int visionName = 0;
		try {
			PackageManager pm = ctx.getPackageManager();
			PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), 0);
			visionName = pi.versionCode;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return visionName;
	}
}
